<template>
	<view class="content">





		<view class="cellBox" style="margin-top: 30upx;">


			<view v-for="(item, index) in contentArr" :key="index" >
				<!-- 	<view class='cell-item-hd' @click="navigateToHandle(item.router)">
			<image class='cell-hd-icon' :src='item.icon'></image>
			<view class='cell-hd-title'>{{ item.name }}</view>
		</view>
		<view class='cell-item-ft'>
			<image class='cell-ft-next icon' src='/static/image/right.png'></image>
		</view> -->


				<view class='cellOneLine' @click="navigateToHandle(item.router)" v-if="item.hiden!=true">
					<view class='cellOneLineLeft'>
						<image mode="scaleToFill" class='iconimageLeft' :src='item.icon'></image>
						<view class='iconleftHint'>{{ item.name }}</view>
					</view>

					<view class="rightViewSmallBox">

						<view class='onelinerightTextView'>{{ item.money }}</view>

						<image class='cell-ft-next icon' src='/static/image/right.png'></image>


					</view>


				</view>


				<view style="width: 100%;height: 2upx;background-color: #eeeeee;"></view>


			</view>



		</view>




	


	</view>
</template>


<script>
	const delay = (function() {
		let timer = 0
		return function(callback, ms) {
			clearTimeout(timer)
			timer = setTimeout(callback, ms)
		}
	})()

	import {
		isMemberWeb
	} from '@/config/config.js'
	import jihaiCopyright from '@/components/jihai-copyright/jihaiCopyright.vue'
	import {
		checkLogin
	} from '@/config/mixins.js'
	export default {
		components: {
			jihaiCopyright
		},

		mixins: [checkLogin],
		data() {
			return {
				open_id: '',
				hasLogin: false,
				userInfo: {}, // 用户信息
				kefupara: '', //客服传递资料
				afterSaleNums: 0,
				isClerk: false,
				isMemberWeb: isMemberWeb,
				alipayNoLogin: true,
				alipayName: '',
				alipayAvatar: '',
				config: '', //配置信息
			
// 1 余额
// 2 积分
// 3 奖金
// 4 回填
// 5 活动币

				contentArr: [{
					name: '余额',
					icon: '/static/image/my/userNavIcon_08.png',
					router: '/pages/member/balance/details',
					money : '',
					hiden: '',
				}, {
					name: '云豆',
					icon: '/static/image/my/userNavIcon_11.png',
					router: '/pages/member/balance/pointRecord',
					money : '',
					hiden: '',
				}, {
					name: '奖金',
					icon: '/static/image/my/userNavIcon_08.png',
					router: '/pages/myCenter/myTeamList/myBonusRecord',
					money : '',
					hiden: '',
				}, {
					name: '回填',
					icon: '/static/image/my/userNavIcon_09.png',
					router: '/pages/myCenter/myTeamList/myhuitian',
					money : '',
					hiden: true,
				}, {
					name: '活动币',
					icon: '/static/image/my/userNavIcon_11.png',
					router: '/pages/myCenter/myTeamList/myActiveMoney',
					money : '',
					hiden: true,

				}, ],



				list: 2,
				suTipStatus: false,
				isNavto: false
			}
		},
		onShow() {


			if (!this.$db.get('userToken') && isMemberWeb) {



				this.checkIsLogin()
				this.isNavto = false;
				return



			}



			this.isNavto = true;
			this.initData()
		},
		methods: {

	

			quitLogin() {
				this.$common.modelShow('退出', '确认退出登录吗?', () => {
					this.$db.del('userToken')
					uni.reLaunch({
						url: '/pages/member/index/index'
					})
				})
			},




			goLogin() {
				uni.navigateTo({
					url: '/pages/login/choose/index'
				})
			},
			getUserInfo(e) {
				let _this = this
				//return false;
				if (e.detail.errMsg == 'getUserInfo:fail auth deny') {
					_this.$common.errorToShow('未授权')
				} else {
					var data = {
						open_id: _this.open_id,
						iv: e.detail.iv,
						edata: e.detail.encryptedData,
						signature: e.detail.signature
					}
					//有推荐码的话，带上
					var invitecode = _this.$db.get('invitecode')
					if (invitecode) {
						data.invitecode = invitecode
					}
					_this.toWxLogin(data)
				}
			},

			getWxCode() {
				let that = this
				uni.login({
					scopes: 'auth_user',
					success: function(res) {
						if (res.code) {
							that.wxLoginStep1(res.code)
						} else {
							this.$common.errorToShow('未取得code')
						}
					},
					fail: function(res) {
						this.$common.errorToShow('用户授权失败wx.login')
					}
				})
			},
			wxLoginStep1(code) {
				this.$api.login1({
					code
				}, res => {
					if (res.status) {
						this.open_id = res.data
					} else {
						this.$common.errorToShow(res.msg, function() {
							uni.navigateBack({
								delta: 1
							})
						})
					}
				})
			},
			aLiLoginStep1(code, user_info) {
				let data = {
					'code': code,
					'user_info': user_info
				}
				this.$api.alilogin1(data, res => {
					this.alipayNoLogin = false;
					if (res.status) {
						this.open_id = res.data.user_wx_id
						//判断是否返回了token，如果没有，就说明没有绑定账号，跳转到绑定页面
						if (!res.data.hasOwnProperty('token')) {
							this.$common.navigateTo('/pages/login/login/index?user_wx_id=' + res.data.user_wx_id);
						} else {
							this.$db.set('userToken', res.data.token)
							this.initData()
						}
					} else {
						this.$common.errorToShow(res.msg)
					}
				})
			},
		
			toLogin() {
				this.$common.navigateTo('../../login/login/index1')
			},
			initData() {
				// 获取用户信息
				var _this = this
		

				if (this.$db.get('userToken')) {
					this.hasLogin = true
					this.$api.userInfo({}, res => {
						if (res.status) {

							console.log(res.data);

			
							
							_this.contentArr[0].money = res.data.balance;
	
							_this.contentArr[1].money = res.data.point;

							_this.contentArr[2].money = res.data.bonus;
							
							if (res.data.backfill==0.00){
								_this.contentArr[3].hiden = true;
							
							}else{
								_this.contentArr[3].money = res.data.backfill;
								_this.contentArr[3].hiden = '';
							}
	
	
							if (res.data.activity_currency==0.00){
								_this.contentArr[4].hiden = true;
	
							}else{
								_this.contentArr[4].money = res.data.activity_currency;
								_this.contentArr[4].hiden = '';
							}
	
				
			

						}
					})
				} else {
					this.hasLogin = false
					// #ifdef MP-WEIXIN
					this.getWxCode()
					// #endif
				}
			},
			navigateToHandle(pageUrl) {

				console.log(pageUrl)


				if (!this.hasLogin) {
					if (this.isNavto) {
						this.checkIsLogin()
						this.isNavto = false;
						return
					}
					return
				}
				// if (!this.hasLogin) {
				// 	delay(() => {
				// 		return this.checkIsLogin()
				// 	}, 500)
				// 	return
				// }

				console.log(pageUrl)

				this.$common.navigateTo(pageUrl)
			},


		},
		computed: {

		},
		watch: {}
	}
</script>

<style lang="scss" scoped>
	.member-top {
		position: relative;
		width: 100%;
		height: 340upx;
		z-index: 98;
	}

	.bg-img {
		position: absolute;
		width: 100%;
		height: 340upx;
		background-color: rgb(238, 85, 92);
	}

	.headerView1 {
		width: 44%;
		height: 100%;
		margin-left: 40upx;
		// background-color: #007AFF;
	}




	.mainRight button {
		background: linear-gradient(to right, #fbcb9a, #ae7741);
		padding: 0 0.3125rem;
		color: #fff;
		font-size: 26upx;
		border-radius: 1.0rem;
		border: 0;
		height: 0.875rem;

		width: 150upx;

		line-height: 60upx;

		margin-top: 40upx;

		height: 60upx;

	}



	.member-top-c {
		position: absolute;
		// background-color: #007AFF;
		width: 100%;
		top: 120upx;
		display: flex;
		flex-direction: row;
		// height: 200upx;
		text-align: center;
	}

	.user-head-img {
		display: block;

		margin-left: 50upx;

		width: 140upx;
		height: 140upx;
		border-radius: 50%;
		overflow: hidden;
		background-color: rgba(255, 255, 255, 0.7);
		// margin: 0 auto 16upx;
	}

	.user-name {
		font-size: 40upx;
		color: #fff;
		font-weight: bold;
		text-align: left;
		margin-top: 20upx;
		// background-color: #007AFF;
	}

	.grade {
		font-size: 24upx;
		color: #fff;
		text-align: left;
		margin-top: 10upx;
	}

	.cellBox {

		position: relative;

		width: 690upx;

		margin-left: 30upx;

		margin-right: 30upx;

		// height: 300upx;

		border-radius: 10upx;

		margin-top: -60upx;
		background: white;
		z-index: 999;
	}


	.member-grid {}




	.member-item-text {

		width: 100%;

		text-align: center;

		height: 60upx;

		line-height: 60upx;

		margin-top: 20upx;


		font-size: 28upx;

		color: #333333;

		font-size: 30upx;
		// background-color: #007AFF;
	}


	.member-item-text2 {

		width: 100%;

		text-align: center;

		height: 60upx;

		line-height: 60upx;

		// margin-top: 20upx;

		margin-bottom: 20upx;


		font-size: 30upx;

		color: rgb(238, 88, 95);
		// background-color: #007AFF;
	}


	.margin-cell-group {
		margin: 20upx 0;
		color: #666666;
	}

	.badge {
		left: 80upx;
		top: -6upx;
	}

	button.cell-item-hd {
		background-color: #fff;
		padding: 0;
		line-height: 1.4;
		color: #333;
	}

	button.cell-item-hd:after {
		border: none;
	}

	.login-btn {
		margin-top: 20upx;
		margin-left: 20upx;
		color: #fff;
		width: 200upx;
		height: 60upx;
		line-height: 60upx;
		border-radius: 30upx;
		background: #938273;
		font-size: 16px;
	}

	.sale-block {
		padding: 0 20upx;
		margin-bottom: 20upx;

		.sale-title {
			height: 72rpx;
			line-height: 72rpx;
			border-bottom: 2rpx solid #f0f0f0;
			display: flex;
			align-items: center;

			.iconfont {
				margin-right: 12upx;
				color: $theme-color;
			}
		}

		.sale-list {
			justify-content: flex-start;
			flex-wrap: wrap;

			.item {
				width: 25%;
				padding: 20upx 0;

				.iconfont {
					font-size: 40upx;
					color: #5e5e5e;
				}

				.text {
					margin-top: 12upx;
					color: #4d4d4d;
					font-size: 24rpx;
					position: relative;
				}
			}

			.tc {
				text-align: center;

				.cell-hd-icon {
					float: none;
					width: 60rpx;
					height: 60rpx;
					margin: 0;
				}
			}
		}
	}

	.coupon {
		top: -40px;
		left: 50px;
	}

	.cellOneLine {

		width: 100%;

		height: 90upx;

		display: flex;

		flex-direction: row;

		justify-content: space-between;


	}

	.cellOneLineLeft {

		width: 70%;

		height: 100%;

		display: flex;

		flex-direction: row;
		// background-color: #007AFF;

	}

	.iconimageLeft {

		height: 40upx;

		width: 40upx;

		// mode : ;

		margin-left: 40upx;

		margin-top: 25upx;

	}

	.iconleftHint {

		height: 90upx;

		line-height: 90upx;


		margin-left: 15upx;

		color: #333333;



		// background-color: #007AFF;


	}

	.onelinerightTextView {

		width: 20%;
		margin-right: 5upx;

		line-height: 90upx;

		font-size: 28upx;

		color: rgb(238, 88, 95);

		text-align: right;

	}


	.btttonView {

		margin-top: 80upx;

		margin-bottom: 40upx;

		display: flex;
		width: 100%;

		display: flex;
		display: -webkit-flex;
		// align-items:center;
		justify-content: center;



	}

	.bt-style {

		background-repeat: no-repeat;
		background-image: url("../../../static/image/logobuttonjianbian.png");

		width: 300upx;
		height: 62upx;
		line-height: 62upx;
		color: white;

		font-weight: 900;

		font-size: 30upx;

		background-size: 100% 100%;

	}

	.rightViewSmallBox {

		display: flex;

		flex-direction: row;

		// background-color: #007AFF;

		justify-content: space-between;

		align-items: center;


	}
</style>
